//
//  OKDoctorCell.m
//  ZLFastDoctor
//
//  Created by answer on 16/5/22.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "OKDoctorCell.h"
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#import <Masonry/Masonry.h>
#import "OKDoctorModel.h"
#import <SDWebImage/UIImageView+WebCache.h>



@interface OKDoctorCell ()

@property (strong, nonatomic) UIImageView *iconView;
@property (strong, nonatomic) UILabel *namelabel;
@property (strong, nonatomic) UILabel *doctortype;
@property (strong, nonatomic) UILabel *hospital;

@property (strong, nonatomic) UIButton *operation_count;
@property (strong, nonatomic) UIButton *flower;
@property (strong, nonatomic) UIButton *banner;

// 匹配度
@property (strong, nonatomic) UIButton *accuracy;

@end

@implementation OKDoctorCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setModel:(OKDoctorModel *)model {
    _model = model;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait] placeholderImage:[UIImage imageNamed:@"illness_img_person.png"] options:SDWebImageRetryFailed];
    self.namelabel.text = model.doctor_name;
    self.doctortype.text = model.doctor_title_name;
    self.hospital.text = model.doctor_hospital_name;
    
    [self.operation_count setTitle:model.operation_count forState:UIControlStateNormal];
    [self.flower setTitle:model.flower forState:UIControlStateNormal];
    [self.banner setTitle:model.banner forState:UIControlStateNormal];
    
    [self.accuracy setTitle:[NSString stringWithFormat:@"匹配度\n 98%%"] forState:UIControlStateNormal];
}

- (void)setupUI {
    
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.namelabel];
    [self.contentView addSubview:self.doctortype];
    [self.contentView addSubview:self.hospital];
    
    [self.contentView addSubview:self.operation_count];
    [self.contentView addSubview:self.flower];
    [self.contentView addSubview:self.banner];
    
    [self.contentView addSubview:self.accuracy];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.contentView).offset(8);
        make.width.height.equalTo(65);
    }];
    
    [self.namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.top.equalTo(self.iconView);
    }];
    
    [self.doctortype makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView);
        make.left.equalTo(self.namelabel.right).offset(20);
    }];
        
    
    [self.hospital makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.top.equalTo(self.namelabel.bottom).offset(5);
    }];
    
    [self.operation_count makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.bottom.equalTo(self.iconView.bottom).offset(5);
    }];
    
    [self.flower makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.operation_count.right).offset(40);
        make.bottom.equalTo(self.iconView.bottom).offset(5);
    }];
    
    [self.banner makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.flower.right).offset(40);
        make.bottom.equalTo(self.iconView.bottom).offset(5);
    }];
    
    [self.accuracy makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.right.equalTo(self.contentView.mas_right).offset(- 60);
        //make.width.height.equalTo(100);
    }];
    
    [self.contentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.bottom.equalTo(self.iconView).offset(8);
    }];
}

- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] init];
        UIImage *image = [UIImage imageNamed:@"illness_img_person.png"];
        _iconView.image = image;
        _iconView.layer.cornerRadius = 32;
        _iconView.clipsToBounds = YES;
    }
    return _iconView;
}

- (UILabel *)namelabel {
    if (_namelabel == nil) {
        _namelabel = [[UILabel alloc] init];
    }
    return _namelabel;
}

- (UILabel *)doctortype {
    if (_doctortype == nil) {
        _doctortype = [[UILabel alloc] init];
        _doctortype.textColor = [UIColor lightGrayColor];
    }
    return _doctortype;
}

- (UILabel *)hospital {
    if (_hospital == nil) {
        _hospital = [[UILabel alloc] init];
        _hospital.textColor = [UIColor lightGrayColor];
        _hospital.font = [UIFont systemFontOfSize:14];
    }
    return _hospital;
}

- (UIButton *)operation_count {
    if (_operation_count == nil) {
        _operation_count = [[UIButton alloc] init];
        [_operation_count setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];
        [_operation_count setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [_operation_count setTitle:@"0" forState:UIControlStateNormal];
    }
    return _operation_count;
}

- (UIButton *)flower {
    if (_flower == nil) {
        _flower = [[UIButton alloc] init];
        [_flower setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];
        [_flower setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [_flower setTitle:@"0" forState:UIControlStateNormal];
    }
    return _flower;
}

- (UIButton *)banner {
    if (_banner == nil) {
        _banner = [[UIButton alloc] init];
        [_banner setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];
        [_banner setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [_banner setTitle:@"0" forState:UIControlStateNormal];
    }
    return _banner;
}

- (UIButton *)accuracy {
    if (_accuracy == nil) {
        _accuracy = [[UIButton alloc] init];
        [_accuracy setBackgroundImage:[UIImage imageNamed:@"pipeidu"] forState:UIControlStateNormal];
        [_accuracy setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _accuracy.titleLabel.font = [UIFont systemFontOfSize:10];
        _accuracy.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
        _accuracy.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    }
    return _accuracy;
}

@end



